package com.huawei.common.entity;

import lombok.Data;

@Data
public class Result<T> {
	private static Integer OK_CODE = 200;
	private static Integer ERROR_CODE = 500;
	private static Integer EMPTY_CODE = 0;
	private static String DEFAULT_ERROR_MSG = "Unknown exception, please contact administrator";

	private String msg;
	private Integer code;
	private T data;
	
    public static<T> Result<T> ok() {
		Result<T> res = new Result<T>();
		res.code = OK_CODE;
		return res;
	}
	
    public static<T> Result<T>  ok(T data) {
		Result<T> res = new Result<T>();
		res.code = OK_CODE;
		res.data = data;
		return res;
	}
    
    public static<T> Result<T> error() {
		Result<T> res = new Result<T>();
		res.code = ERROR_CODE; 
		res.msg = DEFAULT_ERROR_MSG;
		return res;
	}
    
    public static<T> Result<T> error(String msg) {
		Result<T> res = new Result<T>();
		res.code = ERROR_CODE;
		res.msg = msg;
		return res;
	}
    
    public static<T> Result<T> empty() {
		Result<T> res = new Result<T>();
		res.code = EMPTY_CODE; 
		return res;
	}
}
